{extend name="app/admin/view/base.html"/}
{block name="resources"}
<style>
	.fenxiao-header {
		padding: 50px 0 100px 50px;
		font-size: 20px;
		font-weight: 600;
	}
	.layui-form {
		position: relative;
	}
	.layui-form-label {
		text-align: left;
		margin-left: 60px;
	}
	.layui-form-item {
		margin-bottom: 22px;
	}
	.fenxiao-select {
		    position: absolute;
		    left: 550px;
		    top: 135px;
			color: #FF6A00;
	}
	.member-select {
		    position: absolute;
		    left: 550px;
		    top: 195px;
			color: #FF6A00;
	}
</style>
{/block}
{block name="main"}
<div class="fenxiao-header">
	分销商添加
</div>
<div class="layui-form ns-form">
	<div class="layui-form-item">
		<label class="layui-form-label">分销商名称（必填）：</label>
		<div class="layui-input-block">
			<input name="fenxiao_name" type="text" lay-verify="required" class="layui-input ns-len-mid">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">分销商等级：</label>
		<div class="layui-input-inline ns-len-mid">
			<select name="level_id" lay-verify="required"> 
				<option value="">请选择</option>
				{volist name="$level_list" id="level"}
				<option value="{$level.level_id}">{$level.level_name}</option>
				{/volist}
			</select>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">上级分销商：</label>
		<div class="layui-input-inline ns-len-mid">
			<select name="fenxiao_id" lay-filter="fenxiao_id">
				<option value="">请选择</option>
				{volist name="$fenxiao_list" id="fenxiao"}
				<option value="{$fenxiao.fenxiao_id}">{$fenxiao.fenxiao_name}</option>
				{/volist}
			</select>
		</div>
	</div>
	
	<div class="fenxiao-select"></div>
	
	<div class="layui-form-item">
		<label class="layui-form-label">关联会员：</label>
		<div class="layui-input-inline ns-len-mid">
			<select name="member_id" lay-verify="required" lay-filter="member_id">
				<option value="">请选择</option>
				{volist name="$member_list" id="member"}
				<option value="{$member.member_id}">{$member.nickname}</option>
				{/volist}
			</select>
		</div>
	</div>
	
	<div class="member-select"></div>
	
	<div class="ns-form-row">
		<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
		<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
	</div>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
	layui.use(['form', 'laydate'], function() {
		var form = layui.form,
			laydate = layui.laydate,
			repeat_flag = false; //防重复标识
		form.render();
		/**
		 * 监听提交
		 */
		form.on('submit(save)', function(data) {
			console.log(data);
			$.ajax({
				url: ns.url("fenxiao://admin/fenxiao/add"),
				data: data.field,
				dataType: 'JSON', //服务器返回json格式数据
				type: 'POST', //HTTP请求类型
				success: function(res) {
					repeat_flag = false;
					if (res.code == 0) {
						layer.msg(res.message);
						location.href = ns.url("fenxiao://admin/fenxiao/lists")
					} else {
						layer.msg(res.message);
					}
				}
			});
		});
		form.on('select(fenxiao_id)', function(data) {
			var title = $(data.elem).find("option:selected").text();
			console.log(title)
			$(data.elem).parents('.layui-form-item').next('.fenxiao-select').html(title)
		})
		
		form.on('select(member_id)', function(data) {
			var title = $(data.elem).find("option:selected").text();
			console.log(title)
			$(data.elem).parents('.layui-form-item').next('.member-select').html(title)
		})
	})
	
	function back() {
		location.href = ns.url("fenxiao://admin/fenxiao/lists");
	}
</script>
{/block}
